import 'package:flutter/material.dart';
import '../../wonders/config/application.dart';
import '../../wonders/framework.dart';
import '../routers/routes.dart';

//应用上下文件环境
class App extends Application {
  //项目主题
  static ThemeData themeData = ThemeData(primarySwatch: Colors.red);
  static String logDir="/log";
//项目路由初始化
  static Router get router {
    if (Application.router != null) return Application.router;
    final router = new Router();
    Routes.configureRoutes(router);
    Application.router = router;
    return Application.router;
  }
  static navigateToPage(BuildContext context, Widget widget) {
    Navigator.push(context, MaterialPageRoute(builder: (context) => widget));
  }

  static Future navigateTo(BuildContext context, String path,
      {bool replace = false,
        bool clearStack = false,
        TransitionType transition,
        Duration transitionDuration = const Duration(milliseconds: 250),
        RouteTransitionsBuilder transitionBuilder}) {

    String params=path.indexOf("?")>=0?path.substring(path.indexOf("?")):"";
//    LogUtils.instance.log(
//        Log(when: DateTime.now().toString(),what: LogType.Push,tWhere: path,params:params)
//    );
    return Application.router.navigateTo(context, path,
        replace: replace,
        clearStack: clearStack,
        transition: transition,
        transitionDuration: transitionDuration,
        transitionBuilder: transitionBuilder);
  }
  static pop<T>(BuildContext context,[T result]){
//    LogUtils.instance.log(
//        Log(when: DateTime.now().toString(),what: LogType.Pop,fWhere: context.widget.runtimeType.toString())
//    );
    Application.router.pop(context,result);
  }
}
